//package com.matt.repository.impl;
//
//import com.matt.repository.base.BaseNativeSqlRepository;
//import com.matt.repository.base.ChildrenContractRepository;
//import org.apache.commons.lang.StringUtils;
//import org.springframework.stereotype.Service;
//import com.matt.foundation.query.ContractQuery;
//
//import java.util.List;
//import java.util.Objects;
//
///**
// * *******************************
// * Created by Ron.
// * form com.matt
// * on 2017/7/13
// * *******************************
// */
//@Service
//public class ChildrenContractRepositoryImpl extends BaseNativeSqlRepository implements ChildrenContractRepository {
//
//    @Override
//    public List<Object[]> findChildrenCourseByCondition(ContractQuery contractQuery) {
//        String findChildrenCourseSql = "select co.id as courseEarlyId, co.name as courseName, co.duration as courseDuration, co.startDate as startDate, co.endDate as endDate ,co.status as courseStatus,co.price as coursePrice, co.transferredCourseId as transferredCourseId, co.remark, " +
//                " c.id AS childrenId, c.name AS childrenName, c.gender as gender, c.address as address, c.birthday as birthday " +
//                " from children c right join  contract co on co.cid = c.id  WHERE true and c.isDisplayForAdmin = false ";
//        if (StringUtils.isNotBlank(contractQuery.getAreaId())) {
//            findChildrenCourseSql += String.format(" and c.aid= '%s' ", contractQuery.getAreaId());
//        }
//        if (StringUtils.isNotBlank(contractQuery.getChildrenName())) {
//            findChildrenCourseSql += String.format(" and c.name like concat('%s', '%s', '%s')", "%", contractQuery.getChildrenName(), "%");
//        }
//        if (Objects.nonNull(contractQuery.getCourseStatus())) {
//            findChildrenCourseSql += String.format(" and co.status='%s' ", contractQuery.getCourseStatus());
//        }
//        if (StringUtils.isNotBlank(contractQuery.getCourseName())) {
//            findChildrenCourseSql += String.format(" and co.name='%s' ", contractQuery.getCourseName());
//        }
//        findChildrenCourseSql += " order by co.startDate desc " ;
//        findChildrenCourseSql += String.format(" limit %s, %s ", contractQuery.getPageNum()*contractQuery.getPageSize() ,  contractQuery.getPageSize());
//        List<Object[]> objectArrayList = sqlArrayList(findChildrenCourseSql);
//        return objectArrayList;
//    }
//
//    @Override
//    public Long countChildrenCourseByCondition(ContractQuery contractQuery) {
//        String findChildrenCourseSql = "select count(co.id)  " +
//                " from children c right join  contract co on co.cid = c.id  WHERE true and c.isDisplayForAdmin = false";
//        if (StringUtils.isNotBlank(contractQuery.getAreaId())) {
//            findChildrenCourseSql += String.format(" and c.aid='%s' ", contractQuery.getAreaId());
//        }
//        if (StringUtils.isNotBlank(contractQuery.getChildrenName())) {
//            findChildrenCourseSql += String.format(" and c.name like concat('%s', '%s', '%s')", "%", contractQuery.getChildrenName(), "%");
//        }
//        if (Objects.nonNull(contractQuery.getCourseStatus())) {
//            findChildrenCourseSql += String.format(" and co.status='%s' ", contractQuery.getCourseStatus());
//        }
//        if (StringUtils.isNotBlank(contractQuery.getCourseName())) {
//            findChildrenCourseSql += String.format(" and co.name='%s' ", contractQuery.getCourseName());
//        }
//        List objectArrayList = sqlSingleList(findChildrenCourseSql);
//        return Long.valueOf(objectArrayList.get(0).toString());
//    }
//}
